<?php
require_once 'phiction/loader.php';
use \modules\auth\storage as auth;

$ld = new \phiction\schema_loader;
$ld->scan();

$pdo = database::get()->connect();

$migrate = new \phiction\migrate($ld);
$migrate->run($pdo);

$q = new \phiction\query_builder($ld, $pdo);

auth::add_admin($q, 'root', '1234')->run();         // 1
auth::add_user($q, 'hello', 'world')->run();        // 2
auth::add_admin($q, 'editor', 'edit')->run();       // 3

$q->table('post')
    ->field('author', 'title', 'body')
    ->insert(1, 'Hello world!', "first post")   // 1
    ->insert(1, 'Why...?', "Yes.")              // 2
    ->insert(1, 'No', "yes!")                   // 3
    ->run();

$q->table('comment')
    ->field('author', 'post', 'body')
    ->insert(1, 2, "What is the answer to everything?")
    ->insert(2, 2, "42")
    ->run();

foreach (range(1, 12) as $i) {
    $q->table('comment')
        ->field('author', 'post', 'body')
        ->insert(1, 1, "刷爆评论区？$i")
        ->insert(2, 1, "刷爆评论区！$i")
        ->run();
}

/*
$q = new \phiction\query_builder($ld, $pdo);

$q->table('user')
    ->field('login', 'credential')
    ->insert('hello', '123')
    ->insert('foo', '321')
    ->insert('quux', '222')
    ->run();

$q->table('post')
    ->field('author', 'title', 'body')
    ->insert(2, 'Hello world!', "first post")
    ->insert(3, 'Why...?', "Yes.")
    ->insert(3, 'No', "yes!")
    ->run();

$q->table('comment')
    ->field('who', 'post', 'body', 'reply')
    ->insert(1, 1, "Hi there!", null)
    ->insert(2, 1, "Welcome!", 1)
    ->insert(3, 1, "hello!", 1)
    ->insert(3, 1, "hi!", 2)
    ->run();
 */

